/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ImportSettings.java
 *
 * Created on Feb 17, 2011, 3:27:08 PM
 */

package UserInterface;

import env.ImportConfigs;

/**
 *
 * @author Kyle & Chris Leng
 */
public class ImportSettings extends javax.swing.JFrame {

    private UserInterface.GUI __gui;

    /** Creates new form ImportSettings */
    public ImportSettings(UserInterface.GUI _gui) {
        __gui = _gui;
        initComponents();

        // set dialog location on screen
        setDialogLocation();
    }

    /**set dialog location on screen*/
    private void setDialogLocation(){
        int width = this.getWidth();
        int height = this.getHeight();
        int x = __gui.getX() + (int) ((-width + __gui.getWidth()) / 2);
        int y = __gui.getY() + (int) ((-height + __gui.getHeight()) / 2);
        setLocation(x, y);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jCheckBox_NEED_TO_IMPORT_RELATIONSHIP = new javax.swing.JCheckBox();
        jCheckBox_NEED_TO_IMPORT_ATTRIBUTES = new javax.swing.JCheckBox();
        handler = new javax.swing.JCheckBox();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        jPanel7 = new javax.swing.JPanel();
        jButton_cancel = new javax.swing.JButton();
        jButton_continue_to_next_step = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Import Settings");
        setFont(new java.awt.Font("Calibri", 0, 12));

        jPanel2.setLayout(new java.awt.BorderLayout());

        jPanel3.setBorder(javax.swing.BorderFactory.createEmptyBorder(15, 15, 15, 15));
        jPanel3.setLayout(new java.awt.BorderLayout());

        jPanel4.setLayout(new java.awt.GridLayout(3, 1));

        jCheckBox_NEED_TO_IMPORT_RELATIONSHIP.setFont(new java.awt.Font("Calibri", 0, 12));
        jCheckBox_NEED_TO_IMPORT_RELATIONSHIP.setSelected(true);
        jCheckBox_NEED_TO_IMPORT_RELATIONSHIP.setText("Import Relationships");
        jPanel4.add(jCheckBox_NEED_TO_IMPORT_RELATIONSHIP);

        jCheckBox_NEED_TO_IMPORT_ATTRIBUTES.setFont(new java.awt.Font("Calibri", 0, 12));
        jCheckBox_NEED_TO_IMPORT_ATTRIBUTES.setSelected(true);
        jCheckBox_NEED_TO_IMPORT_ATTRIBUTES.setText("Import Attributes");
        jPanel4.add(jCheckBox_NEED_TO_IMPORT_ATTRIBUTES);

        handler.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        handler.setText("Open Schema Handler on Finish");
        jPanel4.add(handler);

        jPanel3.add(jPanel4, java.awt.BorderLayout.CENTER);

        jPanel2.add(jPanel3, java.awt.BorderLayout.CENTER);

        jPanel1.setBackground(new java.awt.Color(51, 102, 255));
        jPanel1.setLayout(new java.awt.BorderLayout());

        jLabel1.setFont(new java.awt.Font("Calibri", 1, 14));
        jLabel1.setText("Import Settings");
        jPanel1.add(jLabel1, java.awt.BorderLayout.CENTER);

        jPanel2.add(jPanel1, java.awt.BorderLayout.PAGE_START);

        jPanel5.setLayout(new java.awt.GridLayout(1, 8));

        jPanel6.setLayout(new java.awt.BorderLayout());
        jPanel5.add(jPanel6);

        jPanel7.setLayout(new java.awt.BorderLayout());
        jPanel5.add(jPanel7);

        jButton_cancel.setFont(new java.awt.Font("Calibri", 0, 12));
        jButton_cancel.setText("Cancel");
        jButton_cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_cancelActionPerformed(evt);
            }
        });
        jPanel5.add(jButton_cancel);

        jButton_continue_to_next_step.setFont(new java.awt.Font("Calibri", 0, 12));
        jButton_continue_to_next_step.setText("Continue");
        jButton_continue_to_next_step.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_continue_to_next_stepActionPerformed(evt);
            }
        });
        jPanel5.add(jButton_continue_to_next_step);

        jPanel2.add(jPanel5, java.awt.BorderLayout.PAGE_END);

        getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton_continue_to_next_stepActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton_continue_to_next_stepActionPerformed
    {//GEN-HEADEREND:event_jButton_continue_to_next_stepActionPerformed
        
        // record user's selection of parameters
        env.Parameters.AnnotationImportSetting.allowImportRelationship = jCheckBox_NEED_TO_IMPORT_RELATIONSHIP.isSelected();
        env.Parameters.AnnotationImportSetting.allowImportAttribute = jCheckBox_NEED_TO_IMPORT_ATTRIBUTES.isSelected();
        env.Parameters.AnnotationImportSetting.needSchemaHandler = handler.isSelected();

        // import annotations from XML or PINS file
        // and then show on screen(in result ediot)
        Thread toRun = new Thread()
        {
            @Override
            public void run() {
                __gui.importAnnotations();

                // clear all attributes value display and disable those buttons as
                // no annotation are selected just after annotations been imported.
                __gui.disableAnnotationDisplay();

                // as we just have extracted and stored annotated classname while
                // importing annotation from xml knowtator files, we should write new
                // found annotated class name into disk.
                config.project.ProjectConf projectconf = new config.project.ProjectConf(
                    env.Parameters.WorkSpace.CurrentProject);
                projectconf.saveConfigure();


                // show all classes in the tree view
                __gui.showAnnotationCategoriesInTreeView_CurrentArticle();
                __gui.showValidPositionIndicators_setAll();
                __gui.showValidPositionIndicators();

                __gui.setNAVCurrentTab(3);

                __gui.totalRefresh();
            }
        };
        toRun.start();
        
        this.dispose();
    }//GEN-LAST:event_jButton_continue_to_next_stepActionPerformed

    private void jButton_cancelActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton_cancelActionPerformed
    {//GEN-HEADEREND:event_jButton_cancelActionPerformed
        this.dispose();
    }//GEN-LAST:event_jButton_cancelActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox handler;
    private javax.swing.JButton jButton_cancel;
    private javax.swing.JButton jButton_continue_to_next_step;
    private javax.swing.JCheckBox jCheckBox_NEED_TO_IMPORT_ATTRIBUTES;
    private javax.swing.JCheckBox jCheckBox_NEED_TO_IMPORT_RELATIONSHIP;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    // End of variables declaration//GEN-END:variables

}
